package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPlanAddDTO;
import org.jsola.hr.dto.AttendPlanUpdateDTO;
import org.jsola.hr.entity.AttendPlanDO;
import org.jsola.hr.query.AttendPlanQuery;
import org.jsola.hr.service.IAttendPlanService;
import org.jsola.hr.vo.AttendPlanVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPlanTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPlanService attendPlanService;

    /**
     * 生成add测试数据
     * @return AttendPlanAddDTO
     */
    public AttendPlanAddDTO getAttendPlanAddDTO(){
        AttendPlanAddDTO attendPlanAddDTO = new AttendPlanAddDTO();
        attendPlanAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPlanAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPlanAddDTO.setName(getRandomValue("varchar",100));
        attendPlanAddDTO.setPlanType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPlanAddDTO.setPunchLocationJson(getRandomValue("text",65535));
        attendPlanAddDTO.setPunchWifiJson(getRandomValue("text",65535));
        attendPlanAddDTO.setOvertimeRule(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPlanAddDTO.setIsSynchLegalHoliday(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPlanAddDTO.setIsRemind(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPlanAddDTO.setRemindBefore(SafeKit.getInteger(getRandomValue("int",0)));
        attendPlanAddDTO.setRemindAfter(SafeKit.getInteger(getRandomValue("int",0)));
        attendPlanAddDTO.setIsTakePhoto(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPlanAddDTO.setIsOnlyPhoto(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPlanAddDTO.setPunchRange(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPlanAddDTO.setIsMakeUp(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPlanAddDTO.setMaxMakeUpCounts(SafeKit.getInteger(getRandomValue("int",11)));
        attendPlanAddDTO.setTakeEffect(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPlanAddDTO.setStartEffectTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        return attendPlanAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPlanUpdateDTO
     */
    public AttendPlanUpdateDTO getAttendPlanUpdateDTO(AttendPlanVO attendPlanVO){
        return attendPlanService.selectDOById(attendPlanVO.getId(), SITE_ID).to(AttendPlanUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPlanQuery
     */
    public AttendPlanQuery getAttendPlanQuery() {
        AttendPlanQuery attendPlanQuery = new AttendPlanQuery();
        List<AttendPlanDO> attendPlanDOList = attendPlanService.list(new AttendPlanDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPlanDOList)) {
            AttendPlanDO attendPlanDO = attendPlanDOList.get(0);
            attendPlanQuery = attendPlanDO.to(AttendPlanQuery.class);
            if (attendPlanDO.getGmtCreate() != null) {
                attendPlanQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPlanDO.getGmtCreate(),-1));
                attendPlanQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPlanDO.getGmtCreate(),1));
            }
            if (attendPlanDO.getGmtModified() != null) {
                attendPlanQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPlanDO.getGmtModified(),-1));
                attendPlanQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPlanDO.getGmtModified(),1));
            }
        }
        return attendPlanQuery;
    }

    /**
     * 保存示例
     * @return AttendPlanVO
     */
    public AttendPlanVO saveAttendPlanExample(){
        AttendPlanAddDTO addDTO = this.getAttendPlanAddDTO();
        AttendPlanVO attendPlanVO = attendPlanService.save(addDTO,buildTokenUser());
        return attendPlanVO;
    }


}

